<template>
  <div id="app">
    <div class="main-content">
      <div class="page-title">{{pageTitle}}</div>
      <vue-page-transition name="fade-in-down">
        <keep-alive include="Home">
          <router-view/>
        </keep-alive>
      </vue-page-transition>
    </div>
    <AppLeftBar class="left-bar"></AppLeftBar>
    <div class="download-container" v-if="currentProgress > 0">
      <el-progress type="circle" :percentage="currentProgress" color="green"></el-progress>
    </div>
  </div>
</template>

<script>
import AppHeader from './components/AppHeader'
import AppFooter from './components/AppFooter'
import AppLeftBar from './components/AppLeftBar'
const APP_IS_RELOADED = 'APP_IS_RELOADED'
export default {
  name: 'App',
  components: {AppLeftBar, AppFooter, AppHeader},
  data () {
    return {
      pageTitle: ''
    }
  },
  computed: {
    currentProgress: function () {
      return this.$store.state.downloadProgress
    },
    appVersion: function () {
      return Number(process.env.VUE_APP_VERSION)
    }
  },
  watch: {
    $route (to, from) {
      console.log('==Page: ', to.meta.title)
      this.pageTitle = to.meta.title
      if (!this.pageTitle) {
        this.pageTitle = from.meta.title
      }
    }
  },
  mounted () {
    this.$store.dispatch('updateDownloadImgProgress', -1)
    console.log('当前版本: ', process.env.VUE_APP_VERSION)
    this.loadAppVersion()
    // this.$message.success('|||||' + window.navigator.userAgent)
    // DiManagerWebView_1000
  },
  destroyed () {
    localStorage.setItem(APP_IS_RELOADED, 'NO')
  },
  methods: {
    loadAppVersion () {
      this.$post('api/AppVersionVc/versions', {}).then(resp => {
        const web = Number(resp.web)
        if (isNaN(web)) {
          return
        }
        const isLoaded = localStorage.getItem(APP_IS_RELOADED)
        if (web > this.appVersion && isLoaded !== 'YES') {
          localStorage.setItem(APP_IS_RELOADED, 'YES')
          window.location.reload()
        }
      }).finally(() => {
      })
    }
  }
}
</script>

<style>
  #app {
    position: relative;
    width: 100%;
    height: 100vh;
  }
  .main-content {
    height: 100%;
    /*border: 1px solid #E4E4E4;*/
    box-sizing: content-box;
    margin-right: 60px;
  }
  .page-title {
    position: absolute;
    top: 8px;
    padding: 6px;
    padding-left: 8px;
    padding-right: 8px;
    /*border: 0px solid lightgray;*/
    border-radius: 20px;
    background: black;
    color: white;
    font-size: 12px;
    font-weight: normal;
    text-align: center;
    left: 50%;
    margin-left: -60px;
    z-index: 20;
    /*box-shadow: 0px 1px 5px 5px rgba(255, 255, 255, 0.1);*/
    min-width: 48px;
    filter: blur(0px); color: white;background: rgba(255, 255, 255, 0.1);
  }
  .left-bar {
    position: absolute;
    top: 0px;
    right: 0px;
    bottom: 0px;
    width: 74px;
    /*border: 1px solid green;*/
    overflow: hidden;
    text-align: center;
    border-left: 1px solid rgba(170,170,170,1);
    z-index: 100;
    background-color: black;
  }
  .download-container {
    background: rgba(0,0,0,0.8);
    position: fixed;
    top: 0px;
    left: 0px;
    width: 99vw;
    height: 100vh;
    box-sizing: content-box;
    color: white;

    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 101;
  }
</style>
